package edu.nf.strategy;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author : LLH
 * @create 2022/1/5
 */
public abstract class AbstractAnnualInspectionStrategy implements AnnualInspectionStrategy {
    /**
     * 获取某年某月的最后一天
     * @param date
     * @return
     */
    protected Date getLastDayOfMonth(Date date) {
        DateTime dateTime = new DateTime(date);
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, dateTime.year());
        //设置月份
        cal.set(Calendar.MONTH, dateTime.month());
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //返回
        return cal.getTime();
    }

    /**
     * 获取车检时间
     * @param registerDate  注册时间
     * @param offSet    偏移值
     * @return
     */
    protected Date getExpDate(Date registerDate,int offSet){
        //当前时间
        Date nowDate = DateUtil.date();
        do{
            registerDate = DateUtil.offsetMonth(registerDate, offSet);
            //System.out.println("=>" + DateUtil.format(registerDate,"yyyy-MM-dd"));
        }while (registerDate.getTime() < nowDate.getTime());
        return registerDate;
    }
}
